<?php
require_once "lib/standard.php";
Globals::init();
$num_of_komotes = $_REQUEST['hiddenkomLength'];
$num_of_rows = $_REQUEST['hiddenRowsLength'];
$egrafes = array();
	$day = "";
	$month = "";
	$year = "";
$query = "INSERT INTO  `hairsalon`.`ergasia` (
`id` ,
`imerominia` ,
`komotis` ,
`ipiresia` ,
`poso`
)
VALUES ";
$koma = "";
foreach($_REQUEST as $key => $val) {
	$komotisId = "";
	$ipiresiaId = "";
	$ipiresiaPoso = "";
	
	if($val) {
		$inputKey = explode("_", $key);
		$type = $inputKey[0];
		$inputVal = explode(",", $val);
		switch ($type) {
			case "day":
				$day = $inputVal[0];
				break;
			case "month":
				$month = $inputVal[0];
				break;
			case "year":
				$year = $inputVal[0];
				break;
			case "data":
				$komotisId = $inputVal[0];
				$ipiresiaId = $inputVal[2];
				$ipiresiaPoso = $inputVal[3] * 100;
				//die($ipiresiaPoso);
				$query .= $koma . "(NULL, '" . $year . "-" . $month . "-" . $day .
					"', '" . $komotisId . "', '" . $ipiresiaId . "', " .  $ipiresiaPoso . ")";
				$koma = ", ";
				break;
			case "hiddenkomLength":
				$num_of_komotes = $inputVal[0];
				break;
			case "hiddenRowsLength":
				$num_of_rows = $inputVal[0];
				break;
				
		}//endswitch
		
	}//endif
	
}
$query .= ";";
echo $query;
$result = mysqli_query(Globals::$db, $query);
//sleep(2);
header("Location: http://" . $_SERVER["SERVER_NAME"] . "/panospanos2/index.php");
?>
